import math
class Solution(object):
    def concatenatedBinary(self, n):
        now_val = 0
        base = 10 ** 9 + 7
        for val in range(1, n + 1):
            m = int(math.log2(val)) + 1
            now_val = now_val * 2 ** m % base + val
        return now_val % base